﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BestLifePOS_Core.Data.Core;
using BestLifePOS_Core.DomainObjects;
using System.Data.SqlClient;
using System.Data;
using BestLifePOS_Core.Exceptions.DataBase;

namespace BestLifePOS_Core.Data.Commands
{
    class BestLifeInsertItemDataAction:BestLifeDataAction<int>
    {
        private Product GvItem;
        private Price_List GvItemPL;
        public BestLifeInsertItemDataAction(Product PItem, Price_List PItemPL)
        {
            GvItem = PItem;
            GvItemPL = PItemPL;

        }

        public override int Body(SqlConnection PConn)
        {
            try
            {
                SqlCommand LvCommand = new SqlCommand();
                LvCommand.Connection = PConn;
                LvCommand.CommandType = CommandType.StoredProcedure;
                LvCommand.CommandText = "dbo.InsertProduct";

                
                   LvCommand.Parameters.Add(new SqlParameter("@Pro_ID",GvItem.Pro_ID.ToString()));
                   LvCommand.Parameters.Add(new SqlParameter("@Cat_ID",GvItem.Cat_ID.ToString()));
                   LvCommand.Parameters.Add(new SqlParameter("@Subcat_ID",GvItem.Subcat_ID.ToString()));
                   LvCommand.Parameters.Add(new SqlParameter("@Brand_Name",GvItem.Brand_Name.ToString()));
                   LvCommand.Parameters.Add(new SqlParameter("@Unit",GvItem.Unit.ToString()));
                   LvCommand.Parameters.Add(new SqlParameter("@Unit_Description",GvItem.Unit_Description.ToString()));
                   LvCommand.Parameters.Add(new SqlParameter("@Description",GvItem.Description.ToString()));
                   LvCommand.Parameters.Add(new SqlParameter("@Pro_Name",GvItem.Pro_Name.ToString()));
                   LvCommand.Parameters.Add(new SqlParameter("@Status",GvItem.Status.ToString()));


                LvCommand.Parameters.Add(new SqlParameter("@User_Id", GvItem.User_Id.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@User_Modify", GvItem.User_Modify.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Date_Create", DateTime.Parse(GvItem.Date_Create.ToString())));
                LvCommand.Parameters.Add(new SqlParameter("@Last_Modify", DateTime.Parse(GvItem.Last_Modify.ToString())));



                LvCommand.Parameters.Add(new SqlParameter("@PL_Id",GvItemPL.PL_Id.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Pro_ID",GvItemPL.PL_Id.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Pro_Price",GvItemPL.PL_Id.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Ret_Price",GvItemPL.PL_Id.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@PV",GvItemPL.PL_Id.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@BV",GvItemPL.PL_Id.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Exp_Date",GvItemPL.PL_Id.ToString()));
             

                LvCommand.Parameters.Add(new SqlParameter("@User_Id", GvItemPL.User_Id.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@User_Modify", GvItemPL.User_Modify.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Date_Create", DateTime.Parse(GvItemPL.Date_Create.ToString())));
                LvCommand.Parameters.Add(new SqlParameter("@Last_Modify", DateTime.Parse(GvItemPL.Last_Modify.ToString())));



                int LvCount = LvCommand.ExecuteNonQuery();
                return LvCount; 
            
            }
            catch(BestlifeDatabaseException e)
            {
                throw new BestlifeDatabaseException(e);
            }

        }

    }
}
